//
//  BKMatchingProvinceViewController.m
//  baokaodaxue
//
//  Created by dangyangyang on 15/5/31.
//  Copyright (c) 2015年 宏图教育. All rights reserved.
//

#import "BKMatchingProvinceViewController.h"
#import "BKResultOfMatchingScoreViewController.h"
#import "BKSearchField.h"
#import "BKMatchingProvViewModel.h"
#import "BKResultOfMatchingProvinceViewController.h"
#import <MBProgressHUD.h>

@interface BKMatchingProvinceViewController ()
@property (weak, nonatomic) IBOutlet BKSearchField *provTextField;
@property (nonatomic ,strong) BKMatchingProvViewModel *viewModel;
@property (weak, nonatomic) IBOutlet BKSearchField *wenliTextField;
@property (weak, nonatomic) IBOutlet BKSearchField *piciTextField;
@property (weak, nonatomic) IBOutlet BKSearchField *leixingTextField;
@end

@implementation BKMatchingProvinceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    _viewModel = [[BKMatchingProvViewModel alloc] init];
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    _provTextField.text = [defaults objectForKey:@"province_pro_text"];
    _wenliTextField.text = [defaults objectForKey:@"province_wenli_text"];
    _piciTextField.text = [defaults objectForKey:@"province_pici_text"];
    _leixingTextField.text = [defaults objectForKey:@"province_leixing_text"];

}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    UITabBarController *tabBarViewController = (UITabBarController *)[[[UIApplication sharedApplication] keyWindow] rootViewController];
    [tabBarViewController.tabBar setBarTintColor:[UIColor colorWithRed:0.459 green:0.839 blue:0.863 alpha:1.000]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)p_back:(id)sender {
    //[self dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)p_submit:(id)sender {
    if ([_provTextField.text length] == 0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请选择省份" delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
    
        [alert show];
        return;
    }
    
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setBool:YES forKey:@"province_change"];
    [defaults setObject:self.provTextField.text forKey:@"province_pro_text"];
    [defaults setObject:self.wenliTextField.text forKey:@"province_wenli_text"];
    [defaults setObject:self.piciTextField.text forKey:@"province_pici_text"];
    [defaults setObject:self.leixingTextField.text forKey:@"province_leixing_text"];
    
    [self.navigationController popViewControllerAnimated:YES];
//    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
//    hud.mode = MBProgressHUDModeIndeterminate;
//    hud.labelText = @"正在加载";
//    [self.view addSubview:hud];
//    [hud show:YES];
    
//    [_viewModel colleageWithProv:_provTextField.text wenli:_wenliTextField.text pici:_piciTextField.text leixing:_leixingTextField.text currentPage:@"1" success:^(NSArray *dataArray) {
//        [hud hide:YES];
//        [hud removeFromSuperview];
//        
//        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//        [defaults setObject:self.provTextField.text forKey:@"province_pro_text"];
//        [defaults setObject:self.wenliTextField.text forKey:@"province_wenli_text"];
//        [defaults setObject:self.piciTextField.text forKey:@"province_pici_text"];
//        [defaults setObject:self.leixingTextField.text forKey:@"province_leixing_text"];
//        BKResultOfMatchingProvinceViewController *result = [[BKResultOfMatchingProvinceViewController alloc] initWithNibName:NSStringFromClass([BKResultOfMatchingProvinceViewController class]) bundle:nil];
//        result.dataSource.dataArray = dataArray;
//        [self.navigationController popViewControllerAnimated:YES];
//        
//        
//    } failure:^(NSString *message) {
//        [hud hide:YES];
//        [hud removeFromSuperview];
//        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:message delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil];
//        [alertView show];
//    }];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
